package com.bjsxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjsxt.domain.EntrustOrder;
import com.bjsxt.domain.TurnoverOrder;
import com.bjsxt.mapper.TurnoverOrderMapper;
import com.bjsxt.service.TurnoverOrderService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class TurnoverOrderServiceImpl extends ServiceImpl<TurnoverOrderMapper, TurnoverOrder> implements TurnoverOrderService {
    /**
     * 分页查询成交记录数据
     *
     * @param page   分页对象<TurnoverOrder>
     * @param userId 用户 ID
     * @param symbol 交易对标识
     * @param type   交易类型:1 买 2卖
     * @return 成交记录集合
     */
    @Override
    public Page<TurnoverOrder> pageByUserIdAndSymbolAndType(Page<TurnoverOrder> page, Long userId, String symbol, Byte type) {
        // 调用分页方法进行数据的查询
        return page(page, new LambdaQueryWrapper<TurnoverOrder>()
                .eq(TurnoverOrder::getBuyUserId, userId)
                .eq(!StringUtils.isEmpty(symbol), TurnoverOrder::getSymbol, symbol)
                .eq(type != null && type != 0, TurnoverOrder::getTradeType, type)
                .or()
                .eq(TurnoverOrder::getSellUserId, userId)
                .eq(!StringUtils.isEmpty(symbol), TurnoverOrder::getSymbol, symbol)
                .eq(type != null && type != 0, TurnoverOrder::getTradeType, type)
                .orderByDesc(TurnoverOrder::getCreated));
    }
}
